package com.example.demowx.model;

import java.time.LocalDateTime;
import java.time.ZoneOffset;

/**
 * @author pengyifeng
 * @version 1.0.0
 * @ClassName AccessToken.java
 * @Description 用于保存微信公众号token
 * @createTime 2020年11月25日 11:28:00
 */
public class AccessToken {

    /**
     * 公众号的全局唯一接口调用凭据
     */
    private String accessToken;
    /**
     *过期时间
     */
    private long expireTime;

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public long getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(long expireTime) {
        this.expireTime = expireTime;
    }

    public AccessToken(String accessToken, String expireIn) {
        super();
        this.accessToken = accessToken;
        this.expireTime = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"))+Integer.parseInt(expireIn)*1000;
    }

    /**
     * 判断token是否过期
     * @return
     */
    public boolean isExpired(){
        return LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"))>expireTime;
    }
}
